package org.example.mockito.transformer;

import java.math.BigDecimal;

import org.example.mockito.model.Order;
import org.example.mockito.model.OrderItem;
import org.example.mockito.model.OrderSummary;

public class OrderToSummaryTransformer {

	public OrderSummary transform(Order order) {

		if (order == null)
			throw new IllegalArgumentException("order param can't be null.");

		OrderSummary result = new OrderSummary();

		Integer itemCount = 0;
		BigDecimal totalAmount = new BigDecimal("0.00");
		for (OrderItem item : order.getOrderItemList()) {
			itemCount += item.getQuantity();

			BigDecimal quantity = new BigDecimal(item.getQuantity());
			BigDecimal itemTotalPrice = quantity.multiply(item.getSellingPrice());
			totalAmount = totalAmount.add(itemTotalPrice);
		}

		result.setItemCount(itemCount);
		result.setOrderNumber(order.getOrderNumber());
		result.setTotalAmount(totalAmount);

		return result;
	}

}
